package com.xxx.video.dynamic.activitys;

import android.os.Bundle;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.xxx.video.R;
import com.xxx.video.commen.activitys.BaseActivity;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.utils.ListUtils;
import com.xxx.video.commen.utils.StatusBarUtil;
import com.xxx.video.commen.views.recyclerviews.RefreshRecyclerView;
import com.xxx.video.dynamic.adapters.RecommendFriendVerticalListAdapter;
import com.xxx.video.dynamic.beans.FriendListBean;
import com.xxx.video.dynamic.presenters.IRecommendFriendView;
import com.xxx.video.dynamic.presenters.RecommendFriendPresenter;

import butterknife.BindView;


public class RecommendFriendActivity extends BaseActivity<RecommendFriendPresenter>
        implements IRecommendFriendView, RefreshRecyclerView.OnRecyclerViewRefreshOrLoadMoreListener,
        BaseRecycleViewAdapter.OnItemClickListener<FriendListBean.PageBean.ListBean> {


    @BindView(R.id.rcv_recommend_friend_list)
    RefreshRecyclerView rcvRecommendFriendList;
    /***
     * page
     */
    private int page = 1;
    /**
     * adapter
     */
    private RecommendFriendVerticalListAdapter mRecommendFriendVerticalListAdapter;

    @Override
    public void initToolbarData() {
        super.initToolbarData();
        showActionBar();
        StatusBarUtil.getInstance().setStatusBarTransparent(this, true);
        setIsShowActionbarLine(true);
        setActionBarTitle(R.string.title_recommend_friend_activity);
    }

    @Override
    protected RecommendFriendPresenter createPresenter() {
        return new RecommendFriendPresenter(this, this);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_recommend_friend;
    }

    @Override
    public void initData(Bundle extras) {
        initList();
        getPresenter().recommendFriends(page);
    }

    @Override
    public void showRootLayoutStatus(int status) {
        showLayoutStatus(status);
    }

    @Override
    public void initList() {
        rcvRecommendFriendList.setLayoutManager(new LinearLayoutManager(this));
        mRecommendFriendVerticalListAdapter = new RecommendFriendVerticalListAdapter(this);
        rcvRecommendFriendList.setAdapter(mRecommendFriendVerticalListAdapter);
        rcvRecommendFriendList.setOnRecyclerViewRefreshOrLoadMoreListener(this);
        mRecommendFriendVerticalListAdapter.setOnItemClickListener(this);
    }

    @Override
    public void initData2View(FriendListBean.PageBean pageBean) {
        showRootLayoutStatus(1);
        rcvRecommendFriendList.resetState();
        if (page == 1) {
            mRecommendFriendVerticalListAdapter.setData(pageBean.list);
            if (ListUtils.isEmpty(pageBean.list)) {
                showRootLayoutStatus(2);
            }
        } else {
            mRecommendFriendVerticalListAdapter.addData(pageBean.list);
        }
        if (!ListUtils.isEmpty(pageBean.list) && pageBean.list.size() < 10) {
            rcvRecommendFriendList.setNoMoreData();
        }
    }

    @Override
    public void startPersonInfoActivity(String userId) {
        Bundle bundle = new Bundle();
        bundle.putString("Id", userId);
        intent2Activity(PersonInfoActivity.class, bundle);
    }

    @Override
    public void addFriendSuccess(int position) {
        if (mRecommendFriendVerticalListAdapter != null) {
            mRecommendFriendVerticalListAdapter.addFriendSuccess(position);
        }
    }

    @Override
    public void onRecyclerviewRefresh() {
        page = 1;
        getPresenter().recommendFriends(page);
    }

    @Override
    public void onRecyclerviewLoadMore() {
        page++;
        getPresenter().recommendFriends(page);
    }

    @Override
    public void onItemClick(FriendListBean.PageBean.ListBean listBean, int position, int type) {
        if (type == 1) {
            getPresenter().addFriends(listBean,position);
        } else{
            startPersonInfoActivity(listBean.userId);
        }
    }
}
